﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
using winS.UnityEditor.ProcessEditor;
using winS.UnityEditor;
using winS.UnityEditor.UIElement;
using System.IO;
//自定义文件的后缀触发这个类本身的OnImportAsset资源可视化
[ScriptedImporter(1, extension)]
public class MiaoTestImporter : ScriptedImporter
{
    public const string extension = "miaotest";

    public static Texture2D icon => Resources.Load<Texture2D>("/Icons/Icon");

    public override void OnImportAsset(AssetImportContext assetImportContext)
    {
        TextAsset textAsset = new TextAsset(File.ReadAllText(assetImportContext.assetPath));
        assetImportContext.AddObjectToAsset("main obj", textAsset, icon);//添加后转为右侧面板可预览
        assetImportContext.SetMainObject(textAsset);
    }

    [MenuItem("Assets/Create/Process Editor/BattleEvent", false)]
    private static void CreateNewProcess()
    {
        ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<Creator>(), $"New BattleEvent.{extension}",null, null);
    }
    internal class Creator : EndNameEditAction
    {
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            //这里创建自己的自定义文件
            EditorProcessAssetManager.Create<MiaoTest>(EditorAssetManager.ProjectPathToFullPath(pathName));
            EditorAssetManager.Refresh();
        }
    }
}

